package com.example.yeujian5.yuejian5.fragment;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;

import com.example.yeujian5.yuejian5.R;
import com.example.yeujian5.yuejian5.activity.ClubSearchActivity;
import com.example.yeujian5.yuejian5.adapter.ClubAdapter;

import java.util.ArrayList;
import java.util.List;

public class ClubFragment extends Fragment {
    private View view=null ;
    private TabLayout tabs;
    private ImageButton search;
    private ViewPager viewPager;
    private List<String> mTitle = new ArrayList<String>();
    private List<Fragment> mFragment = new ArrayList<Fragment>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_club, container, false);
        initViews();
        initEvents();
        initData();
        ClubAdapter adapter = new ClubAdapter(getChildFragmentManager(), mTitle, mFragment);
        viewPager.setAdapter(adapter);
        //为TabLayout设置ViewPager
        tabs.setupWithViewPager(viewPager);
        //使用ViewPager的适配器
//        tabs.setTabsFromPagerAdapter(adapter);

        return view;
    }

    private void initViews() {
        tabs = (TabLayout) view.findViewById(R.id.tab02);
        viewPager = (ViewPager) view.findViewById(R.id.viewPager);
        search=(ImageButton)view.findViewById(R.id.c_search);
    }

    private void initEvents() {

        search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new Intent(getActivity(),ClubSearchActivity.class);
                startActivity(intent);
            }
        });

    }

    private void initData() {
        mTitle.add("最具人气");
        mTitle.add("离我最近");
        mFragment.add(new ClubPopFragment());
        mFragment.add(new ClubNearFragment());
     /*   getUserId();*/
    }
   /* private void getUserId(){
        Intent intent = getActivity().getIntent();
        userid = intent.getStringExtra("uid");
//        Toast.makeText(getActivity(),userid,Toast.LENGTH_SHORT).show();
    }*/
}